﻿using System;
using System.Windows.Forms;

namespace CardsSimulator
{
    public partial class Form1 : Form , IView, IObserver
    {
        private IController controller;
        private CardGame model;

        public Form1()
        {
            InitializeComponent();
            controller = new GameController(this);
        }

        private void hostujGręToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                controller.CreateGame(dialog.FileName);
            }
        }

        private void dołączDoGryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            controller.JoinGame();
        }

        void IObserver.Update()
        {
            //this.Text = model.Name;
        }

        public void SetModel(CardGame _model)
        {
            this.model = _model;
        }

        public void InitView()
        {
            this.Text = model.Name;
            for (int i=0;i<model.Desk.Count;i++)
            {
                Component temp = model.Desk[i];
                ComponentBox b = new ComponentBox();
                b.Text = temp.Name;
                b.DoubleClick += b_DoubleClick;
                b.SetBounds(Width/2+(i*75),Height/2,50,50);
                this.Controls.Add(b);
            }
            //for (int i = 0; i < model.NumberOfPlayers; i++)
            //{
            //    for (int j = 0; j < model.Players[i].Components.Count; j++)
            //    {
            //        Component temp = model.Players[i].Components[j];
            //        ComponentBox b = new ComponentBox();
            //        b.Text = temp.Name;
            //        b.SetBounds(Width / 2 + (i * 75), Height / 2, 50, 50);
            //        this.Controls.Add(b);
            //    }
            //}
        }

        void b_DoubleClick(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
